
<template>
  <div class="main-container">
    <div class="filtrate-bar">
      <div class="title-box">
        <div class="icon-box">
          <span class="wk wk-my-task icon" />
        </div>
        <span class="text">全国运营周报   {{ fromDate.substr(0,10) + '~' + thruDate.substr(0,10)}}</span>
      </div>
    </div>

    <div class="table-content">
      <div class="handle-bar">
        <!-- <a-button class="export-btn">导出</a-button> -->
      </div>
      <a-table :scroll="{ x: 1200, y: 300 }" :columns="fieldList" :data-source="tableList" bordered :pagination="false">
        <span slot="physicalFreezeRate" slot-scope="text, record">
          {{ record.physicalFreezeRate + '%' }}
        </span>
        <span slot="physicalRefrigerateRate" slot-scope="text, record">
          {{ record.physicalRefrigerateRate + '%' }}
        </span>
        <span slot="physicalConstantRate" slot-scope="text, record">
          {{ record.physicalConstantRate + '%' }}
        </span>
        <span slot="physicalNormalRate" slot-scope="text, record">
          {{ record.physicalNormalRate + '%' }}
        </span>
        <span slot="physicalTotalRate" slot-scope="text, record">
          {{ record.physicalTotalRate + '%' }}
        </span>
      </a-table>
    </div>

    <div class="analysis">
      <a-row :span="24">
        <a-col :span="24"
          ><div class="analysis-content">
            <div id="strockBu" /></div
        ></a-col>
      </a-row>

      <a-row :span="24">
        <a-col :span="24"
          ><div class="analysis-content">
            <div id="strockBu2" /></div
        ></a-col>
      </a-row>
    </div>

    <div class="content"></div>
  </div>
</template>

<script>
import { httpAction, getAction } from '@/api/manage'
export default {
  /** 客户总量分析 */
  name: 'SummaryReportAll',
  data() {
    return {
      loading: false,
      fromDate: '',
      thruDate: '',
      chartAnalysis1: null,
      chartAnalysis2: null,
      analysis1Option: null,
      analysis1Option2: null,
      url: {
        getSalesDataTotalAnalysis: '/online/api/getCrmWmsDataReport',
      },
      postParams: {}, // 筛选参数
      dataIndex: null,
      list: [],
      axisList: [],
      fieldList: [
        {
          title: '部门',
          align: 'center',
          dataIndex: 'warehouseName',
          key: 'warehouseName',
          width: 80,
          fixed: 'left',
        },

        {
          title: '托盘总数（P)',
          align: 'center',
          fixed: 'left',
          children: [
            {
              title: '冷冻',
              align: 'center',
              dataIndex: 'buildingFreeze',
              key: 'buildingFreeze',
              width: 90,
            },
            {
              title: '冷藏',
              align: 'center',
              dataIndex: 'buildingRefrigerate',
              key: 'buildingRefrigerate',
              width: 90,
            },
            {
              title: '恒温',
              align: 'center',
              dataIndex: 'buildingConstant',
              key: 'buildingConstant',
              width: 90,
            },
            {
              title: '常温',
              align: 'center',
              dataIndex: 'buildingNormal',
              key: 'buildingNormal',
              width: 90,
            },
            {
              title: '全温区',
              align: 'center',
              dataIndex: 'buildingTotal',
              key: 'buildingTotal',
              width: 90,
            },
          ],
        },
        {
          title: '运营数据',
          align: 'center',
          children: [
            {
              title: '冷冻占用',
              align: 'center',
              dataIndex: 'physicalFreeze',
              key: 'physicalFreeze',
              width: 90,
            },
            {
              title: '空库位',
              align: 'center',
              dataIndex: 'availableFreeze',
              key: 'availableFreeze',
              width: 90,
            },
            {
              title: '库存率',
              align: 'center',
              dataIndex: 'physicalFreezeRate',
              key: 'physicalFreezeRate',
              width: 90,
              scopedSlots: { customRender: 'physicalFreezeRate' },
            },
            {
              title: '冷藏占用',
              align: 'center',
              dataIndex: 'physicalRefrigerate',
              key: 'physicalRefrigerate',
              width: 90,
            },
            {
              title: '空库位',
              align: 'center',
              dataIndex: 'availableRefrigerate',
              key: 'availableRefrigerate',
              width: 90,
            },
            {
              title: '库存率',
              align: 'center',
              dataIndex: 'physicalRefrigerateRate',
              key: 'physicalRefrigerateRate',
              width: 90,
              scopedSlots: { customRender: 'physicalRefrigerateRate' },
            },
            {
              title: '恒温占用',
              align: 'center',
              dataIndex: 'physicalConstant',
              key: 'physicalConstant',
              width: 90,
            },
            {
              title: '空库位',
              align: 'center',
              dataIndex: 'availableConstant',
              key: 'availableConstant',
              width: 90,
            },
            {
              title: '库存率',
              align: 'center',
              dataIndex: 'physicalConstantRate',
              key: 'physicalConstantRate',
              width: 90,
              scopedSlots: { customRender: 'physicalConstantRate' },
            },
            {
              title: '常温占用',
              align: 'center',
              dataIndex: 'physicalNormal',
              key: 'physicalNormal',
              width: 90,
            },
            {
              title: '空库位',
              align: 'center',
              dataIndex: 'availableNormal',
              key: 'availableNormal',
              width: 90,
            },
            {
              title: '库存率',
              align: 'center',
              dataIndex: 'physicalNormalRate',
              key: 'physicalNormalRate',
              width: 90,
              scopedSlots: { customRender: 'physicalNormalRate' },
            },
          ],
        },
        {
          title: '周平均库存占用（P）',
          align: 'center',
          children: [
            {
              title: '全温区',
              align: 'center',
              dataIndex: 'physicalTotal',
              key: 'physicalTotal',
              width: 150,
            },
          ],
        },
        {
          title: '周平均库存率',
          align: 'center',
          children: [
            {
              title: '全温区',
              align: 'center',
              dataIndex: 'physicalTotalRate',
              key: 'physicalTotalRate',
              width: 150,
              scopedSlots: { customRender: 'physicalTotalRate' },
            },
          ],
        },
      ],
      tableList: [],
    }
  },
  computed: {
    // 列表请求参数
    listPostParams() {
      const params = { ...this.postParams }

      if (this.dataIndex !== undefined && this.dataIndex !== null) {
        const dataItem = this.axisList[this.dataIndex]
        delete params.type
        params.startTime = dataItem.type
        params.endTime = dataItem.type
      }

      return params
    },
  },
  mounted() {
    this.initAxis()
  },
  methods: {
    /**
     * 搜索点击
     */
    searchClick(params) {
      this.postParams = params
      this.getDataList()
    },
    /**
     * 图表数据   待完善
     */
    getDataList() {
      this.chartAnalysis1.setOption(this.analysis1Option, true)
      this.chartAnalysis2.setOption(this.analysis2Option, true)
    },

    /** 图表 */
    initAxis() {
      this.chartAnalysis1 = this.echarts.init(document.getElementById('strockBu'))
      this.chartAnalysis2 = this.echarts.init(document.getElementById('strockBu2'))
      this.analysis1Option = {
        title: {
          text: '库位利用率',
        },
        dataZoom: [{ // 控制图表左右滑动
				    width: '15',
				    type: 'slider',
				    show: false, //flase直接隐藏图形
				    xAxisIndex: [0],
				    left: 33, //滚动条靠左侧的百分比
				    bottom: 40,
				    height: 20,//组件高度  
				    start: 0,//滚动条的起始位置
				    showDataShadow: false,//是否显示数据阴影
				    showDetail: false,//是否显示想洗数值信息
				    end: 50 //滚动条的截止位置（按比例分割你的柱状图x轴长度）
				}, { 
				    type: 'inside',
				    show: true,
				    xAxisIndex: [0],
				    start: 0,//滚动条的起始位置
				    end: 0.25 //滚动条的截止位置（按比例分割你的柱状图x轴长度）
				}],
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            // 坐标轴指示器，坐标轴触发有效
            type: 'shadow', // 默认为直线，可选为：'line' | 'shadow'
          },
          formatter: function (params, ticket, callback) {
            console.log(params)
            var htmlStr = ''
            for (var i = 0; i < params.length; i++) {
              var param = params[i]
              var xName = param.name
              var seriesName = param.seriesName
              var value = param.value
              var color = param.color
              if (i === 0) {
                htmlStr += xName + '<br/>'
              }
              htmlStr += '<div>'
              htmlStr +=
                '<span style="margin-right:5px;display:inline-block;width:10px;height:10px;border-radius:5px;background-color:' +
                color +
                ';"></span>'
              htmlStr += seriesName + '：' + value + '%'
              htmlStr += '<div/>'
            }
            return htmlStr
          },
        },
        legend: {
          data: ['冷冻', '冷藏', '恒温', '常温'],
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true,
        },
        xAxis: [
          {
            axisLabel: {
              interval: 0,
              rotate: 30,
            },
            type: 'category',
            data: [],
          },
        ],
        yAxis: [
          {
            type: 'value',
            axisLabel: {
              formatter: '{value}%',
            },
          },
        ],
        series: [
          {
            name: '冷冻',
            type: 'bar',
            color: '#0000FF',
            emphasis: {
              focus: 'series',
            },
            label: {
              show: true,
              position: 'top',
              formatter: '{@[0]}%',
            },
            data: [12, 12, 25, 36, 84],
          },
          {
            name: '冷藏',
            type: 'bar',
            color: '#FFFF00',
            emphasis: {
              focus: 'series',
            },
            label: {
              show: true,
              position: 'top',
              formatter: '{@[0]}%',
            },
            data: [12, 12, 25, 36, 84],
          },
          {
            name: '恒温',
            type: 'bar',
            color: '#00980d',
            emphasis: {
              focus: 'series',
            },
            label: {
              show: true,
              position: 'top',
              formatter: '{@[0]}%',
            },
            data: [12, 12, 25, 36, 84],
          },
          {
            name: '常温',
            type: 'bar',
            color: '#800080',
            label: {
              show: true,
              position: 'top',
              formatter: '{@[0]}%',
            },
            data: [12, 12, 25, 36, 84],
            emphasis: {
              focus: 'series',
            },
          },
        ],
      }
      this.analysis2Option = {
        title: {
          text: '库存托数',
        },
        dataZoom: [{ // 控制图表左右滑动
				    width: '15',
				    type: 'slider',
				    show: false, //flase直接隐藏图形
				    xAxisIndex: [0],
				    left: 33, //滚动条靠左侧的百分比
				    bottom: 40,
				    height: 20,//组件高度  
				    start: 0,//滚动条的起始位置
				    showDataShadow: false,//是否显示数据阴影
				    showDetail: false,//是否显示想洗数值信息
				    end: 50 //滚动条的截止位置（按比例分割你的柱状图x轴长度）
				}, { 
				    type: 'inside',
				    show: true,
				    xAxisIndex: [0],
				    start: 0,//滚动条的起始位置
				    end: 0.25 //滚动条的截止位置（按比例分割你的柱状图x轴长度）
				}],
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            // 坐标轴指示器，坐标轴触发有效
            type: 'shadow', // 默认为直线，可选为：'line' | 'shadow'
          },
          formatter: function (params, ticket, callback) {
            console.log(params)
            var htmlStr = ''
            for (var i = 0; i < params.length; i++) {
              var param = params[i]
              var xName = param.name
              var seriesName = param.seriesName
              var value = param.value
              var color = param.color
              if (i === 0) {
                htmlStr += xName + '<br/>'
              }
              htmlStr += '<div>'
              htmlStr +=
                '<span style="margin-right:5px;display:inline-block;width:10px;height:10px;border-radius:5px;background-color:' +
                color +
                ';"></span>'
              htmlStr += seriesName + '：' + value 
              htmlStr += '<div/>'
            }
            return htmlStr
          },
        },
        legend: {
          data: ['冷冻', '冷藏', '恒温', '常温'],
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true,
        },
        xAxis: [
          {
            axisLabel: {
              interval: 0,
              rotate: 30,
            },
            type: 'category',
            data: [],
          },
        ],
        yAxis: [
          {
            type: 'value',
          },
        ],
        series: [
          {
            name: '冷冻',
            type: 'bar',
            color: '#0000FF',
            emphasis: {
              focus: 'series',
            },
            label: {
              show: true,
              position: 'top',
            },
            data: [12, 12, 25, 36, 84],
          },
          {
            name: '冷藏',
            type: 'bar',
            color: '#FFFF00',
            emphasis: {
              focus: 'series',
            },
            label: {
              show: true,
              position: 'top',
            },
            data: [12, 12, 25, 36, 84],
          },
          {
            name: '恒温',
            type: 'bar',
            color: '#00980d',
            emphasis: {
              focus: 'series',
            },
            label: {
              show: true,
              position: 'top',
            },
            data: [12, 12, 25, 36, 84],
          },
          {
            name: '常温',
            type: 'bar',
            color: '#800080',
            label: {
              show: true,
              position: 'top',
            },
            data: [12, 12, 25, 36, 84],
            emphasis: {
              focus: 'series',
            },
          },
        ],
      }
      const param = {}
      param.onlyBu = 'Y'
      getAction(this.url.getSalesDataTotalAnalysis, param).then((res) => {
        this.fromDate = res.result.workMap.fromDate
        this.thruDate = res.result.workMap.thruDate

        let buList = []
        let physicalFreezeRateList = []
        let physicalRefrigerateRateList = []
        let physicalConstantRateList = []
        let physicalNormalRateList = []


        let physicalFreeze = []
        let physicalRefrigerate = []
        let physicalConstant = []
        let physicalNormal = []


        res.result.workMap.dataListByWarehouse.forEach((e) => {
          buList.push(e.warehouseName)
          physicalFreezeRateList.push(e.physicalFreezeRate)
          physicalRefrigerateRateList.push(e.physicalRefrigerateRate)
          physicalConstantRateList.push(e.physicalConstantRate)
          physicalNormalRateList.push(e.physicalNormalRate)

          physicalFreeze.push(e.physicalFreeze)
          physicalRefrigerate.push(e.physicalRefrigerate)
          physicalConstant.push(e.physicalConstant)
          physicalNormal.push(e.physicalNormal)
        })
        this.tableList = res.result.workMap.dataListByWarehouse
        this.analysis1Option.xAxis[0].data = buList
        this.analysis2Option.xAxis[0].data = buList
        this.analysis1Option.series[0].data = physicalFreezeRateList
        this.analysis1Option.series[1].data = physicalRefrigerateRateList
        this.analysis1Option.series[2].data = physicalConstantRateList
        this.analysis1Option.series[3].data = physicalNormalRateList
        this.analysis2Option.series[0].data = physicalFreeze
        this.analysis2Option.series[1].data = physicalRefrigerate
        this.analysis2Option.series[2].data = physicalConstant
        this.analysis2Option.series[3].data = physicalNormal
        this.$nextTick(() => {
          this.getDataList()
        })
      })
    },

    /**
     * 导出点击
     */
    exportClick() {
      this.requestExportInfo(biCustomerTotalListExportAPI, this.listPostParams)
    },
  },
}
</script>


<style lang="less" scoped>
/deep/ .ant-table-thead > tr > th,
.ant-table-tbody > tr > td {
  padding: 10px 4px;
}
.main-container {
  border: 1px solid #e6e6e6;
  border-radius: 2px;
  background-color: white;
  height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  position: relative;
}

.filtrate-bar {
  background-color: white;
  padding: 15px 20px 5px 20px;
  margin-right: 15px;
  line-height: 34px;
  .icon-box {
    width: 34px;
    height: 34px;
    text-align: center;
    line-height: 34px;
    color: #168a40;
    background-color: #dfe8ff;
    border-radius: 50%;
    margin-right: 10px;
    float: left;
  }
  .text {
    font-size: 17px;
    font-weight: 700;
  }
}

.content-title {
  padding: 10px 20px 5px;
  font-size: 16px;
  color: #333;
}
.analysis {
  margin-top: 10px;
  .analysis-content {
    padding: 8px 10px;
    #strockBu {
      margin: 0 auto;
      width: 95%;
      height: 400px;
    }

     #strockBu2 {
      margin: 0 auto;
      width: 95%;
      height: 400px;
    }
    
  }
}

.axis-content {
  padding: 20px 10% 40px;
  position: relative;
}

.table-content {
  padding: 0 30px 20px 30px;
}

.export-button {
  float: right;
  margin-right: 22px;
}

// 导出操作bug
.handle-bar {
  margin-bottom: 8px;
  text-align: right;
}

.search-box {
  padding-right: 15px;
}

.radio-box {
  padding: 0 20px;
  margin-bottom: 15px;
  /deep/ .el-radio__label {
    color: #99a9bf !important;
  }
}

.static {
  padding: 0 20px;
  margin-bottom: 10px;
  .text {
    font-size: 13px;
    color: #99a9bf;
    display: inline-block;
  }
  .text:not(:last-child) {
    margin-right: 15px;
  }
}
/deep/ .ant-table-wrapper {
  border: 1px solid #ebeef5;
}
/deep/ .ant-table-placeholder {
  display: none;
}
</style>

